<?php
//
// +------------------------------------------------------------------------+
// | Gecko Framework                                                        |
// +------------------------------------------------------------------------+
//

/**
 * Tells the renderer if the current view will use
 * the global template
 *
 * @param boolean $bool_has If the layout has a template
 */
function hasLayout( $bool_has ) {
	Gecko_Template::setParam('hasLayout', $bool_has );
}

/**
 * Sets the page Title (if rendering the global template)
 *
 * @param string $title
 */
function setTitle( $title ) {
	Gecko_Template::setParam('pageTitle', $title );
}

/**
 * Adds a new CSS class to the template
 * Only if using the global template
 *
 * @param unknown_type $css_file
 */
function addCSS( $css_file ) {
	Gecko_Template::pushParam( 'css', $css_file );
}

/**
 * Include a partial template (named _$template)
 *
 * @param string $template
 */
function includePartial( $template ) {
	$vars = Zend_Registry::get( 'base' )->getView()->getVars();
	echo Gecko_Template::renderTemplate( "_" . $template, $vars );
}

/**
 * DEPRECATED
 * Returns a debug String
 *
 * @return string
 */
function _debugInfo() {
	if( defined( "DEBUG_MODE" ) && DEBUG_MODE ) {

	}

	return "";
}

/**
 * Renders into template the Session
 * messages
 *
 * @return string
 */
function _includeSessionMessages() {
	echo Gecko_Utils::displayMsg();
}

/**
 * Includes the main body into the template
 *
 * @return string
 */
function _includeBody() {
	echo Gecko_Template::getParam('body');
}

/**
 * Includes the page Title
 *
 */
function _includeTitle() {
	$title = Gecko_Template::getParam('pageTitle');

	echo "<title>$title</title>\n";
}

/**
 * Includes the javascript registered libraries
 *
 * @return string
 */
function _includeJavascript() {
	$libJS = Gecko_Template::getJavascriptLibs();

	if( is_array( $libJS ) ) {
		foreach( $libJS as $lib ) {
			echo $lib . "\n";
		}
	}
}

/**
 * Includes the added CSS files
 *
 * @return string
 */
function _includeCSS() {
	$cfg = Zend_Registry::get('config');
	$cssDir = $cfg->pageRootURL . "/web/css/%s";
	$mainCSS = $cfg->Template->css;
	if( !empty( $mainCSS ) ) {
		$css = sprintf( $cssDir, $mainCSS );
		echo '<link rel="stylesheet" type="text/css" href="' . $css . '" media="screen" />' . "\n";
	}
	$cssFiles = Gecko_Template::getParam( 'css' );
	if( is_array( $cssFiles ) ) {
		foreach( $cssFiles as $cssFile ) {
			$css = sprintf( $cssDir, $cssFile );
			echo '<link rel="stylesheet" type="text/css" href="' . $css . '" />' . "\n";
		}
	}
}
?>